- Read/Write Images
- Visualization of Images
- Inhomogeneity/Bias Field Correction
- Skull Stripping/Brain Extraction
- Image Registration
- Tissue-Class Segmentation
- Image operations
February 19, 2015
oro.dicom - read/write DICOM data, the nifti object
dcm2niir - uses dcm2nii from Chris Rorden
matlabr - could use dicomread matlab code and excecute through RMedical Imaging Task View
oro.nifti: read/write data, the nifti objectfslr: process data (need FSL for most of the functionality)ANTsR: process data (full toolbox)extrantsr: makes ANTsR work with nifti objectsdti - adaptive smoothing and diffusion tensor tools
fmri - post-processing analysis: linear models and p-value smoothingAnalyzeFMRI - fMRI analysis (last updated in 2013)spm12r package calls out MATLAB using SPM
Multi-modal dataset from HAMMER, (NIfTI conversion from ANALYZE).
Data from https://www.nitrc.org/frs/?group_id=187 (testing folder in White_Matter_Lesion_Segmentation_Testdata.zip)
4 MRI sequences: T1-weighted, T2-weighted, PD, FLAIR
files
t1 t2 pd flair
"T1.nii.gz" "T2.nii.gz" "PD.nii.gz" "FLAIR.nii.gz"
fslr: readnii uses oro.nifti::readNIfTI:
library(fslr) base_t1 = readnii(files["t1"])
library(fslr) fslr::ortho2(base_t1)
over_50 = mask_img(base_t1, base_t1 > 40); ortho2(base_t1, over_50)
image(base_t1, z = 55, plot.type = "single")
over_50[over_50 <= 0] = NA; over_50 = cal_img(over_50) overlay(base_t1, over_50, z = 55, plot.type = "single")
ANTsR/extrantsr
bias_correct from extrantsr package calls ANTsR::n4BiasFieldCorrectionlibrary(extrantsr) n4_t1 = bias_correct(file = base_t1, correction = "N4", retimg = TRUE)
fslr: Uses method by Sled, Zijdenbos, and Evans (1998) (slow)
bc_t1 = fsl_biascorrect(file = base_t1)
FSLDIR='/usr/local/fsl/'; export FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; $FSLDIR/bin/fast -B --nopve --out="/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpa4mKOM/file15e6f7f9ff9a7" "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpa4mKOM/file15e6f60841581.nii.gz";
ratio = finite_img(n4_t1 / base_t1) ortho2(n4_t1, ratio, col.y = alpha(hotmetal(), 0.5))
ss_t1 = fslbet(n4_t1, outfile = "SS_Image")
FSLDIR='/usr/local/fsl/'; export FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; $FSLDIR/bin/bet2 "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpa4mKOM/file15e6f2126f0db.nii.gz" "./SS_Image"
mask = ss_t1 > 0
ortho2(base_t1, y = mask, col.y = alpha("red", 0.5))
cropped = dropEmptyImageDimensions(ss_t1) image(cropped, z = floor(dim(cropped)[3]/2), plot.type = "single")
rgl, misc3d (contour3d function)brainR - put on a webpage with some controls http://bit.ly/grid_braindevtools::source_gist("bd40d10afabc503d71e8")
ANTsR/extrantsr
antsRegistration - rigid/affine/non-linear diffeomorphicextrantsr::registration - wraps antsRegistration to use nifti objectsfslr
flirt - linear/affine registrationfnirt - non-linear registration (need affine first)fnirt_with_affine - wraps above 2
ants_reg_flair = registration( filename = files["flair"], template.file = n4_t1, typeofTransform = "Rigid")
template.file = mni_fname(mm = "1", brain = TRUE) ss_t1_to_mni = registration( filename = ss_t1, template.file = template.file, typeofTransform = "SyN", remove.warp = FALSE, outprefix = "temp")
reg_flair_to_mni = ants_apply_transforms( fixed = template.file, moving = ants_reg_flair$outfile, # registered FLAIR interpolator = "Linear", transformlist = ss_t1_to_mni$fwdtransforms )
We can develop pipelines/full analyses!
extrantsr::preprocess_mri_within will do inhomogeneity correction, skull strip (or mask), and register to the first scan.
proc_images = preprocess_mri_within(
files = files[c("t1", "t2", "pd", "flair")],
maskfile = ss_t1 > 0)
preprocess_mri_across combines preprocess_mri_within and registration. If you had baseline/follow-up data:
outfiles = gsub("[.]nii", '_process.nii', files)
preprocess_mri_across(
baseline_files = files[c("base_t1", "base_t2", "base_pd", "base_flair")],
followup_files = files[c("f_t1", "f_t2", "f_pd", "f_flair")],
baseline_outfiles = outfiles[c("base_t1", "base_t2", "base_pd", "base_flair")],
followup_outfiles = outfiles[c("f_t1", "f_t2", "f_pd", "f_flair")],
maskfile = "Brain_Mask.nii.gz")
ANTsR/extrantsr: uses Atropos
ANTsR - atropos, extrantsr - otropostissue_seg = otropos( a = ss_t1, x = mask)
fslr: uses FAST
--nobias as an option does not do bias field correction (if already done)fast_t1 = fast(ss_t1, opts = "--nobias")
FSLDIR='/usr/local/fsl/'; export FSLDIR; sh "${FSLDIR}/etc/fslconf/fsl.sh"; FSLOUTPUTTYPE=NIFTI_GZ; export FSLOUTPUTTYPE; $FSLDIR/bin/fast --nobias --out="/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpa4mKOM/file15e6f60cbfee3" "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpa4mKOM/file15e6f682913b1.nii.gz";
See alos spm12r_segment
fslr
fslsmooth - Gaussian/box smoothingfslerode/fsldilate - erosion/dilationfslfill/fslfill2 - fill holesspm12r
spm_bwlabel - label connected componentsANTsR
smooth_image - Gaussian smoothingoMath("ME")/oMath("MD") - erosion/dilationoMath("FillHoles") - fill holesoMath("GetLargestComponent") - find largest componentsfsl_slicetimer - slice timing correctionANTsR::preprocessfMRIspm12r
Sled, John G, Alex P Zijdenbos, and Alan C Evans. 1998. “A Nonparametric Method for Automatic Correction of Intensity Nonuniformity in MRI Data.” Medical Imaging, IEEE Transactions on 17 (1). IEEE: 87–97.